/*
 * author: Yu Xia <rainsia@163.com>                                            *
 * created: 2023-04-28                                                         *
 */

import Layout from '@/views/Layout.vue';

import {createRouter, RouterOptions, Router, RouteRecordExtra, createWebHashHistory} from 'vue-router'
export const commonRoutes: RouteRecordExtra[] = [
  {
    /**
     * process the redirect
     */
    path: '/redirect/:path(.*)', name: "Redirect", component: () => import('@/views/Redirect.vue'), hidden: true
  },
  {
    path: '/login', name: "Login", component: () => import('@/views/Login.vue'), hidden: true
  },
  { path: '/', name: 'Layout', component: Layout, redirect: "/index",
    children: [{
      path: 'index', name: "Index", component: () => import('@/views/index.vue'),
      meta: { title: '首页', icon: 'home', affix: true }
    }]
  },
  // { path: '/about', name: 'About', component: Layout, redirect: "noredirect",
  //   children: [{
  //     path: 'index', name: 'About', component: () => import('@/views/About.vue'),
  //     meta: { title: '关于', icon: 'dashboard', affix: false }
  //   }]
  // }
];

export const dynamicRoutes: RouteRecordExtra[] = [
  { path: '/test/data', name: 'TestData', component: Layout, redirect: "noredirect",
    children: [{
      path: 'index', name: 'TestData', component: () => import('@/views/test/data/TestData.vue'),
      meta: { title: '演示数据', icon: 'dashboard', affix: false }
    }]
  },
];

const options: RouterOptions = {
  // history: createWebHistory(import.meta.env.VITE_APP_CONTEXT_PATH),
  history: createWebHashHistory(),
  routes: commonRoutes,
  // keep scrollbar position when refreshing
  scrollBehavior(/*to*/_, /*from*/__, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { top: 0 };
    }
  }
};

const router: Router = createRouter(options);

export default router;
